package edu.pku.sei.transformation.tgg.adapter;

import java.util.ArrayList;
import java.util.List;

import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.model.Rule;
import edu.pku.sei.transformation.editor.model.TypedModel;
import edu.pku.sei.transformation.tgg.rule.IModelParameter;
import edu.pku.sei.transformation.tgg.rule.IRule;
import edu.pku.sei.transformation.tgg.rule.ITGGTransformation;

public class TGGAdapter implements ITGGTransformation {

	AtomicTransformation element;
	List<IModelParameter> modelParameters = new ArrayList<IModelParameter>();
	List<IRule> rules = new ArrayList<IRule>();
	IRule axion;

	public TGGAdapter(AtomicTransformation trans) {
		this.element = trans;
		for (TypedModel typedModel : element.getTypedModel()) {
			modelParameters.add(new ModelParameterAdapter(typedModel));
		}

		for (Object obj : element.getRules()) {
			if (obj instanceof Rule) {
				IRule rule = new RuleAdapter((Rule) obj, this);
				rules.add(rule);
				if (((Rule) obj).getPriority() == 1)
					this.axion = rule;
			}
		}
	}

	@Override
	public List<IModelParameter> getModelParameters() {
		return modelParameters;
	}

	@Override
	public IRule getAxiom() {
		return axion;
	}

	@Override
	public List<IRule> getRules() {
		return rules;
	}

	@Override
	public String getID() {
		return String.valueOf(element.getElementID());
	}

	@Override
	public String getName() {
		return element.getName();
	}

}
